#!/bin/bash
set -eu
export TMPDIR=/var/tmp
INSTALL_PREFIX="/usr/local"
if [[ $# -gt 0 ]]; then
    INSTALL_PREFIX=$1
fi

echo "Using INSTALL_PREFIX=${INSTALL_PREFIX}"



WORKPATH=`mktemp -d`
cp prerequisites/openssl-1.1.1d.tar.gz ${WORKPATH}
cd ${WORKPATH}
tar -zxvf openssl-1.1.1d.tar.gz
cd openssl-1.1.1d
./config --prefix=/usr/local --openssldir=/usr/local/openssl
make -j `lscpu | grep "^CPU(" | awk '{print $2}'`
sudo make install
sudo apt install ca-certificates
sudo rm -f /usr/bin/openssl
sudo rm -f /usr/lib/x86_64-linux-gnu/libcrypto.so
sudo ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
sudo ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib/libssl.so.1.1
sudo ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib/libcrypto.so.1.1
sudo ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib/x86_64-linux-gnu/libcrypto.so
